package com.lst.tools.basics.utils;

import org.apache.commons.codec.binary.Hex;
import java.security.MessageDigest;

/**
 * @author: Frank
 * @date: 2019/12/30 16:00
 * @version: V1.0
 */
public class EncryptUtils {

    /***
     * SHA256加密
     * @param str 加密后的报文
     * @return
     */
    public static String getSHA256Str(String str){
        String encryptCode = "";
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            byte[] hash = messageDigest.digest(str.getBytes("UTF-8"));
            encryptCode = Hex.encodeHexString(hash);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encryptCode;
    }
}
